/*
 * @Descripttion: 
 * @version: 
 * @Author: Andy
 * @Date: 2020-09-15 09:56:17
 * @LastEditors: Andy
 * @LastEditTime: 2020-09-24 16:25:10
 */
import { UI_Listen } from '../../config/ui_def'


cc.Class({
    extends: cc.Component,

    properties: {
        bg_node: cc.Node,
        equip_node: cc.Node,
        unlock_node: cc.Node,
        highLight: cc.Node,
        mask_node: cc.Node,
        head_sp: cc.Sprite,
    },

    // LIFE-CYCLE CALLBACKS:
    clearAllItem() {
        for (let i = (this.equip_node.children.length); i > 0; i--) {
            he.pool.putElement('roleEquipItem', this.equip_node.children[i - 1])
        }
    },

    init(info, index) {
        this.clearAllItem()
        if (index >= 0) this.index = index
        if (info) {
            this.roleInfo = info.msg
            let Spname = `juesexuanze${this.roleInfo.id - 1000}`
            this.head_sp.spriteFrame = he.load.get('rolePage', cc.SpriteAtlas, 'plist').getSpriteFrame(Spname)
            this.canClick = false
            this.highLight.active = false
            this.lock = !info.isHave
            if (info.isHave) {
                //已解锁
                this.equip_node.active = true
                this.unlock_node.active = false
                this.mask_node.active = false
                this.canClick = true
                for (let i = 0; i < this.roleInfo.equips.length; i++) {
                    let pre = he.pool.getElement('roleEquipItem')
                    pre.parent = this.equip_node
                    pre.getComponent('roleEquipItem').initItem(this.roleInfo, i)
                }
            } else {
                //未解锁的状态
                this.equip_node.active = false
                this.unlock_node.active = true
                this.mask_node.active = true
                //w未解锁也能点击
                this.canClick = true
            }
        }
    },

    showLight() {
        this.highLight.active = true
    },

    hideLight() {
        this.highLight.active = false
    },

    clickServer() {
        if (this.canClick) {
            gg.eventManager.emit('rolePage', { type: UI_Listen.ROLE_BIG_CHOOSE, index: this.index, info: this.roleInfo, isLock: this.lock })
        }
    }

});
